1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
import pika
username = 'username' password = 'password' host = '127.0.0.1' port = 5672 vhost = '/vhost' queue = 'request' body = '{"type":null,"body":[{"contractNo":"111","masFlag":"N"}]}'
credentials = pika.PlainCredentials(username, password)
parameters = pika.ConnectionParameters( host=host, port=port, virtual_host=vhost, credentials=credentials)
properties = pika.spec.BasicProperties(content_type="text/plain")
conn = pika.BlockingConnection(parameters)
try: with conn.channel() as chan: chan.basic_publish( exchange='', routing_key=queue, properties=properties, body=body, ) print(1) except Exception: raise finally: conn.close()
|